package org.mm.model;

import static org.mm.parameter.enm.EnumRole.*;

import java.io.Serializable;
import javax.persistence.*;

import java.util.List;


/**
 * The persistent class for the roles database table.
 *
 */
@Entity
@Table(name="roles")
public class Role implements Serializable {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -4687632937476903534L;

	@Id
	@Column(name="role_id")
	private Long roleId;

	@Column(name="role_authority")
	private String roleAuthority;

	@Column(name="role_description")
	private String roleDescription;

	@Column(name="role_name")
	private String roleName;

	@Version
	@Column(name="role_version")
	private int roleVersion;

/*	//bi-directional many-to-one association to User
	@OneToMany(mappedBy="role", fetch=FetchType.LAZY)
	private List<User> users;*/

	public Role() {
	}

	public Long getRoleId() {
		return this.roleId;
	}

	public void setRoleId(Long roleId) {
		this.roleId = roleId;
	}

	public String getRoleAuthority() {
		return this.roleAuthority;
	}

	public void setRoleAuthority(String roleAuthority) {
		this.roleAuthority = roleAuthority;
	}

	public String getRoleDescription() {
		return this.roleDescription;
	}

	public void setRoleDescription(String roleDescription) {
		this.roleDescription = roleDescription;
	}

	public String getRoleName() {
		return this.roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public int getRoleVersion() {
		return this.roleVersion;
	}

	public void setRoleVersion(int roleVersion) {
		this.roleVersion = roleVersion;
	}

/*	public List<User> getUsers() {
		return this.users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}*/

/*	public User addUser(User user) {
		getUsers().add(user);
		user.setRole(this);

		return user;
	}

	public User removeUser(User user) {
		getUsers().remove(user);
		user.setRole(null);

		return user;
	}*/

	public boolean isAdmin() {
		return roleId != null && roleId.intValue() == ROLE_ADMIN.id;
	}

	public boolean isDoctor() {
		return roleId != null && roleId.intValue() == ROLE_DOCTOR.id;
	}

	public boolean isPatient() {
		return roleId != null && roleId.intValue() == ROLE_PATIENT.id;
	}

}